<template>
  <div class="lendRecord">
    <BasicContainer>
      <FyCurd
        ref="crud"
        :page.sync="page"
        :data="tableData"
        :permission="permissionList"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange" />
    </BasicContainer>
  </div>
</template>

<script>
  import { lendRecordPage } from '@/api/personnel/certificateinfo'
  import { mapState } from 'vuex'

  export default {
    name: 'Fypersonnelcertificateinfo',
    props: {
      certificateInfoId: {
        type: String
      }
    },
    data() {
      return {
        searchForm: {},
        tableData: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条
          layout: 'total, sizes, prev, pager, next'
        },
        tableLoading: false,
        tableOption
      }
    },
    computed: {
      ...mapState('user', ['permissions']),
      permissionList() {
        return {
          addBtn: this.$isEmpty(this.permissions.personnel_fypersonnelcertificateinfo_add, false),
          delBtn: this.$isEmpty(this.permissions.personnel_fypersonnelcertificateinfo_del, false),
          editBtn: this.$isEmpty(this.permissions.personnel_fypersonnelcertificateinfo_edit, false)
        }
      }
    },
    methods: {
      // 列表查询
      getList(page, params) {
        this.tableLoading = true
        lendRecordPage(
          Object.assign(
            {
              current: page.currentPage,
              size: page.pageSize
            },
            params,
            this.searchForm
          ),
          this.certificateInfoId
        )
          .then(response => {
            this.tableData = response.data.data.records
            this.page.total = response.data.data.total
            this.tableLoading = false
          })
          .catch(() => {
            this.tableLoading = false
          })
      },
      // 每页条数改变事件
      sizeChange(pageSize) {
        this.page.pageSize = pageSize
      },
      // 当前页发生改变事件
      currentChange(current) {
        this.page.currentPage = current
      },
      // 查询事件
      searchChange(form, done) {
        this.searchForm = form
        this.page.currentPage = 1
        this.getList(this.page, form)
        done()
      },
      // 刷新事件
      refreshChange() {
        this.getList(this.page)
      },
      // 打开借出对话框
      openLendDialog() {
        this.visibleCertifiLendDialog = true
      },
      // 选择用户详细信息
      showSelectUserInfo() {}
    }
  }
  export const tableOption = {
    border: true,
    index: true,
    indexLabel: '序号',
    stripe: true,
    menu: false,
    addBtn: false,
    searchMenuSpan: 6,
    column: [
      {
        type: 'input',
        label: '申请人',
        prop: 'applicant',
        span: 12,
        width: 80
      },
      {
        type: 'date',
        label: '申请时间',
        prop: 'applyDate',
        width: 100,
        span: 12
      },
      {
        type: 'date',
        label: '使用时间',
        width: 100,
        prop: 'useTime',
        span: 12
      },
      {
        type: 'date',
        label: '预计归还时间',
        prop: 'expectReturnDate',
        span: 12,
        width: 100
      },
      {
        type: 'input',
        label: '实际归还时间',
        width: 200,
        prop: 'actualReturnTime',
        span: 12
      },
      {
        type: 'textarea',
        label: '说明',
        prop: 'instruction',
        span: 12
      }
    ]
  }
</script>

<style>
  .lendRecord {
    max-width: 1000px;
  }
</style>
